package com.siruier.boss.api

import com.siruier.boss.api.core.ApiHelper
import com.siruier.boss.api.core.ResultBean
import com.siruier.boss.bean.*
import kotlinx.coroutines.CoroutineScope
import retrofit2.http.Body
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST

val TASK_API_SERVICE: TaskApiService by lazy { ApiHelper.create(TaskApiService::class.java) }

val CoroutineScope.taskApi get() = TASK_API_SERVICE

interface TaskApiService {

    /**
     * 获取Content
     */
    @POST("/api/task/content")
    @FormUrlEncoded
    suspend fun taskContent(
        @Field("deviceInfo") deviceInfo: String,
        @Field("device") device: String = "android",
    ): ResultBean<TaskContent?>

    /**
     * 获取应用列表
     */
    @POST("/api/task/appList")
    suspend fun appList(@Body body: TaskAppListParam?): ResultBean<PageBean<AppTask>?>

    /**
     * 抢任务
     */
    @POST("/api/task/robTask")
    suspend fun robTask(@Body body: TaskAppListParam?): ResultBean<RobTask?>

    /**
     * 放弃任务
     */
    @POST("/api/task/giveUpTask")
    suspend fun giveUpTask(@Body body: TaskAppListParam?): ResultBean<Any?>

    /**
     * 获取审核中的任务记录
     */
    @POST("/api/task/auditTaskList")
    @FormUrlEncoded
    suspend fun auditTaskList(
        @Field("currentPage") currentPage: Int = 1,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<TaskAuditDetail>?>

    /**
     * 获取已发放的任务记录
     */
    @POST("/api/task/hisTaskList")
    @FormUrlEncoded
    suspend fun hisTaskList(
        @Field("currentPage") currentPage: Int = 1,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<UserHisTask>?>
}